home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
TransSkel.cpt
/
FakeAlert.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-01-08
|
5KB
|
173 lines
{ In-memory item list for dialog with four items:}
{ 1 "^0^1^2^3" (static text)}
{ 2 Button 1}
{ 3 Button 2}
{ 4 Button 3}
{ The caller of FakeAlert passes the four strings that are to be}
{ substituted into the first item, the number of buttons that}
{ should be used, and the titles to put into each button.}
{ A copy of the item list is hacked to use the right number of}
{ buttons.}
{ Thanks to Erik Kilk and Jason Haines. Some of the stuff to do}
{ this is modified from code they wrote.}
{ Ported to LightSpeed Pascal 8 January 1987 Owen Hartnett }
UNIT FakeAlert;
INTERFACE
FUNCTION FakeAlert (s1, s2, s3, s4 : Str255;
nButtons, defButton : integer;
t1, t2, t3 : Str255) : integer;
IMPLEMENTATION
VAR
ItemList : ARRAY[0..32] OF integer;
savePort : GrafPtr;
theDialog : DialogPtr;
iListHandle : Handle;
bounds : Rect;
itemHit : integer;
PROCEDURE InitItemList;
{This proc performs static initializations on ItemList }
BEGIN
Itemlist[0] := 3; { max number of items - 1 }
Itemlist[1] := 0; { statText item}
{ reserve a long for item handle }
itemlist[2] := 0; { display rectangle }
Itemlist[3] := 10;
Itemlist[4] := 27;
itemlist[5] := 61;
Itemlist[6] := 225;
Itemlist[7] := $8808; { 8 + 128 = statText (disabled), title 8 bytes long }
itemlist[8] := $5e30; { ^0^1^2^3 }
Itemlist[9] := $5e31;
Itemlist[10] := $5e32;
itemlist[11] := $5e33;
{ first button}
Itemlist[12] := 0; { reserve a long for item handle }
Itemlist[13] := 0;
itemlist[14] := 104; { display rectangle }
Itemlist[15] := 140;
Itemlist[16] := 124;
itemlist[17] := 210;
Itemlist[18] := $400; { 4 = pushButton, title is 0 bytes long}
{ second button}
Itemlist[19] := 0; { reserve a long for item handle }
itemlist[20] := 0;
Itemlist[21] := 104; { display rectangle }
Itemlist[22] := 30;
itemlist[23] := 124;
Itemlist[24] := 100;
Itemlist[25] := $400; { 4 = pushButton, title is 0 bytes long}
{ third button}
itemlist[26] := 0; { reserve a long for item handle }
Itemlist[27] := 0;
Itemlist[28] := 72; { display rectangle }
itemlist[29] := 30;
Itemlist[30] := 92;
Itemlist[31] := 100;
itemlist[32] := $400; { 4 = pushButton, title is 0 bytes long}
END;
{ Set dialog button title and draw bold outline if makeBold true.}
{ This must be done after the window is shown or else the bold}
{ outline won't show up (which is probably the wrong way to do it).}
PROCEDURE SetDControl (theDialog : DialogPtr;
itemNo : integer;
title : Str255;
makeBold : Boolean);
VAR
itemHandle : Handle;
itemType : integer;
itemRect : Rect;
pState : PenState;
BEGIN
GetDItem(theDialog, itemNo, itemType, itemHandle, itemRect);
SetCTitle(ControlHandle(itemHandle), title);
IF makeBold THEN
BEGIN
GetPenState(pState);
PenNormal;
PenSize(3, 3);
InsetRect(itemRect, -4, -4);
FrameRoundRect(itemRect, 16, 16);
SetPenState(pState);
END;
END;
{ Fake an alert, using an in-memory window and item list.}
{ The message to be presented is constructed from the first}
{ four arguments. nButtons is the number of buttons to use,}
{ defButton is the default button, the next three args are}
{ the titles to put into the buttons. The return value is}
{ the button number (1..nButtons). This must be interpreted}
{ by the caller, since the buttons may be given arbitrary}
{ titles.}
{ nButtons should be between 1 and 3, inclusive.}
{ defButton should be between 1 and nButtons, inclusive.}
FUNCTION FakeAlert;
VAR
savePort : GrafPtr;
theDialog : DialogPtr;
iListHandle : Handle;
bounds : Rect;
itemHit : integer;
BEGIN
InitItemList;
InitCursor;
GetPort(savePort);
iListHandle := NewHandle(longint(512));
HLock(iListHandle);
ItemList[0] := nButtons; { = number items - 1 }
BlockMove(@ItemList[0], iListHandle^, longint(512));
SetRect(bounds, 115, 80, 355, 220);
theDialog := NewDialog(NIL, bounds, '', false, dBoxProc, WindowPtr(-1), false, longint(0), iListHandle);
ParamText(s1, s2, s3, s4); { construct message }
SetPort(theDialog);
ShowWindow(theDialog);
CASE nButtons OF { set button titles }
3 :
BEGIN
SetDControl(theDialog, 4, t3, defButton = 3);
SetDControl(theDialog, 3, t2, defButton = 2);
SetDControl(theDialog, 2, t1, defButton = 1);
END;
2 :
BEGIN
SetDControl(theDialog, 3, t2, defButton = 2);
SetDControl(theDialog, 2, t1, defButton = 1);
END;
1 :
SetDControl(theDialog, 2, t1, defButton = 1);
END;
{ ModalDialog returns 1 if return/enter hit, which, since}
{ the statText item is first, can be unambiguously}
{ interpreted as "choose default".}
ModalDialog(NIL, itemHit);
IF itemHit = 1 THEN
itemHit := defButton
ELSE
itemHit := itemHit - 1;
HUnlock(iListHandle);
DisposDialog(theDialog);
SetPort(savePort);
FakeAlert := itemHit;
END;
END.